<?php
class AccountLicenceLogic
{
private $aclFile = '';
private $aclData = array();
public function __construct()
{
$this->aclFile = DATA_PATH.'account.licence.php';
}
public function LicenceDSP()
{
$html="";
/*$aclData = $this->Account();
$licence = $aclData['licence'];
$licence['expiresDSP'] = $licence['expires'] <0 ?'': ('[ 服务到期时间：'.date('Y年m月d日',$licence['expires']).' ]');
$html = "程序授权类型：<b>{$licence['type']}</b> {$licence['expiresDSP']}";
if (!$licence['public'])
{
$html .= "&nbsp;&nbsp;&nbsp;&nbsp;
<a href=\"javascript:;\" onclick=\"$('#comlic_special_setting').toggle('fast')\">商业版特殊设置</a>
<div id=\"comlic_special_setting\" style=\"display:none;padding:0px 60px;border:2px dashed #ccc;\">
是否显示版权信息：<font class=\"ini\" src=\"licence.dsp.cc\"></font>
&nbsp;&nbsp;&nbsp;（注：版权信息指前台页面最底部的Powered相关文字和链接）
<br/>
是否显示商业授权信息：<font class=\"ini\" src=\"licence.dsp.comlic\"></font>
&nbsp;&nbsp;&nbsp;强烈建议您开启显示商业授权信息，可以彰显网站身份，提升网站可信度
</div>";
$html .= ui('loader')->js('#admin/js/sdb.parser');
}
$html .= '<div id="lic_recommend" style="display:none;"></div>';
$lrcmd = $licence['public'] ?'m': ($licence['expires'] >0 ?'c': 'q');
$html .= '<script type="text/javascript">var lrcmd = "'.$lrcmd.'";</script>';*/
return $html;
}
public function Account()
{
if (!is_file($this->aclFile))
{
return $this->aclDataDefault();
}
$this->aclDataInizd();
return $this->aclData;
}
public function Signup($account,$password)
{	

	 $response = request('signup',array('account'=>$account,'password'=>$password),$error);
	
	if (is_array($response) &&isset($response['account']) &&isset($response['token']))
	{	
	$this->aclDataInizd();
	$this->aclData['account'] = $response['account'];
	$this->aclData['token'] = $response['token'];
	$this->aclData['licence'] = $response['licence'];
	$this->aclData['upgrade'] = $response['upgrade'];
	$this->aclDataApply();
	return 'ok';
	}
	return $response; 
}
public function ccDSP()
{
/*$aclData = $this->Account();
$licence = $aclData['licence'];
if ($licence['public']) return true;
$ccdsp = ini('licence.dsp.cc');
return $ccdsp;*/
return '';
}
public function Comlic()
{
/*$aclData = $this->Account();
$licence = $aclData['licence'];
if ($licence['public']) return '';
if (!ini('licence.dsp.comlic')) return '';
$urlBase = ini('settings.site_url');
return '<a href="http://cenwor.com/plugin.php?id=license:view&license_id='.$licence['id'].'&url_hash='.$licence['hash'].'" title="商业授权验证" target="_blank"><img src="'.$urlBase.'/static/images/tttuangou.license.gif" /></a>';*/
return '';
}
public function RPSFailed($content)
{
if ($content == 'acl.denied')
{
return true;
}
return false;
}
private function aclDataDefault()
{
return array(
'account'=>'',
'token'=>'',
'licence'=>array(
'type'=>'试用版',
'public'=>true,
'expires'=>-1
),
'upgrade'=>array(
'pr'=>1,
'stop'=>false
)
);
}
private function aclDataInizd()
{
if ($this->aclData) return;
$licString = include_once $this->aclFile;
$this->aclData = $this->licEncrypt($licString,'DECODE');
}
private function aclDataApply()
{
$aclDataExport = '<?php /* CENWOR.USER.LICENCE.CACHE */ return "'.$this->licEncrypt($this->aclData,'ENCODE').'"; ?>';
file_put_contents($this->aclFile,$aclDataExport);
}
public function licEncrypt($tar,$ops = 'ENCODE')
{
$skey = md5('<<< CENWOR.USER.LICENCE.CACHE.SECKEY >>>');
if ($ops == 'ENCODE')
{
return authcode(base64_encode(serialize($tar)),'ENCODE',$skey);
}
else
{
return unserialize(base64_decode(authcode($tar,'DECODE',$skey)));
}
}
}
?>